package com.ferryc.fegin.hystrix;

import com.ferryc.entity.User;
import com.ferryc.fegin.UserFeignClient;
import com.ferryc.model.Result;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/*
*
 * Created by Ferry Chen on 2019/11/13.
*/

@Component
@Slf4j
public class UserServiceFallbackFactory implements FallbackFactory<UserFeignClient> {

    @Override
    public UserFeignClient create(Throwable e) {
        log.error("fallBack,reson: " + e.getMessage());
        return new UserFeignClient() {
            @Override
            public Result add(String username) {
                return Result.fail("新增失败");
            }

            @Override
            public Result<List<User>> queryUser() {
                return Result.fail("查询失败");
            }
        };
    }
}
